import styled, { createGlobalStyle, keyframes } from 'styled-components'

const Button = styled.button<{ primary?: boolean }>`
  background-color: ${props => props.primary ? 'red' : 'blue'};
  color: white;
`
// 继承
const ErrorButton = styled(Button)`
  background-color: pink;
  border-radius: 5px;
`

const Input = styled.input.attrs(props => {
  return {
    type: 'number',
    defaultValue: props.defaultValue
  }
})`
  border: 1px solid #ccc;
`

// 全局样式
const GlobalStyle = createGlobalStyle`
  body {
    background-color: skyblue;
  }
`

const move = keyframes`
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(100px);
  }
`

const Box = styled.div`
  width: 100px;
  height: 100px;
  background-color: red;
  animation: ${move} 1s linear infinite;
`

export default function CSSInJS() {
  return (
    <>
      <h1>CSS in JS</h1>
      <Button primary>CSS in JS</Button>
      <ErrorButton>Error Button</ErrorButton>
      <Input defaultValue={500} />
      <GlobalStyle></GlobalStyle>
      <Box></Box>
    </>
  )
}